<?php  
class ProductController extends AuthController{
	private $db;//模型
	private $goods_gid;//商品主键id
	/**
	 * 构造函数
	 * @return [type] [description]
	 */
	public function __init(){
		$this->db=K('Product');//货品模型
		$this->goods_gid=Q('goods_gid',0,'intval');//商品id
	}
	
	/**
	 * 货品管理
	 */
	public function manage(){
		if (IS_POST) {
			if ($this->db->addProduct()) {
				$this->success('操作成功');
			}else{
				$this->error($this->db->error);
			}
		}else{
			//获取当前商品属性名
			$attr=$this->db->getAttr($this->goods_gid);

			//获取已添加的货品
			$product=$this->db->getProduct($this->goods_gid);
			// p($product);exit;
			$this->assign('attr',$attr);
			$this->assign('product',$product);
			$this->display();
		}
	}

	/**
	 * 删除货品
	 * @return [type] [description]
	 */
	public function delProduct(){
        if ($this->db->delPoduct()) {

            echo json_encode(array( 'state' => 1 , 'msg' => '删除成功', 'timeout' => 0.1));exit;

        } else {

            echo json_encode(array( 'state' => 0 , 'msg' => '删除失败', 'timeout' => 0.1));exit;  

        }
    }
}
?>